<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>更多</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      body {
        background-color: rgba(105, 105, 105, 0.16);
      }
      ul,
      li {
        list-style: none;
      }
      ul {
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
        align-items: center;
      }
      li {
        width: 15%;
        height: 32%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
      }
      li img {
        width: 100%;
        height: 60%;
      }
      p {
        width: 100%;
        margin-top: 10px;
        font-size: 30px;
        text-align: center;
      }
      div {
        width: 50px;
        height: 50px;
        background-color: rgba(42, 41, 40, 0.411);
        position: fixed;
        right: 30px;
        bottom: 30px;
        line-height: 25px;
        color: white;
        display: none;
      }
    </style>
  </head>
  <body>
    <h1>更多商品</h1>
    <ul></ul>
    <p>︾</p>
    <div>回　到顶　部</div>
    <script src="./js/axios.js"></script>
    <script>
      let URL = "http://localhost:8888";
      let listUl = document.querySelector("ul");
      let op = document.querySelector("p");
      let oDiv = document.querySelector("div");
      let num = 1;
      axios
        .get(URL + "/goods/list", {
          params: {
            current: num,
            pagesize: 42,
          },
        })
        .then((r) => {
          let data = r.data;
          let str = "";
          console.log(data);
          if (data.code == 1) {
            data.list.forEach((s) => {
              str += `<li>
                 <a href="detail.html?pid=${s.goods_id}"> <img src="${
                s.img_big_logo
              }" alt="" /></a>
                  <span>
                    ${s.title.substring(0, 4)}
                    </span>
                  <span>${s.current_price}</span>
                </li>`;
            });
            listUl.innerHTML = str;
          }
        });
      // 加
      function numList() {
        num++;
        axios
          .get(URL + "/goods/list", {
            params: {
              current: num,
              pagesize: 12,
            },
          })
          .then((r) => {
            let data = r.data;
            let str = "";
            console.log(data);
            if (data.code == 1) {
              data.list.forEach((s) => {
                str += `<li>
                 <a href="detail.html?pid=${s.goods_id}"> <img src="${
                  s.img_big_logo
                }" alt="" /></a>
                  <span>
                    ${s.title.substring(0, 4)}
                    </span>
                  <span>${s.current_price}</span>
                </li>`;
              });
              listUl.innerHTML += str;
            }
          });
      }
      op.onclick = function () {
        numList();
      };
      //   监听滚动条
      onscroll = function () {
        let scrollTop =
          document.documentElement.scrollTop || document.body.scrollTop;
        let ks = document.documentElement.clientHeight;
        if (scrollTop > ks) {
          oDiv.style.display = "block";
          // numList();
        } else {
          oDiv.style.display = "none";
        }
        // console.log(scrollTop, ks);
      };
      oDiv.onclick = function () {
        let timer = setInterval(() => {
          let s = document.documentElement.scrollTop;
          //   console.log(s);
          if (s > 0) {
            document.documentElement.scrollTop =
              document.documentElement.scrollTop - 10;
          } else {
            clearInterval(timer);
          }
        }, 20);
      };
    </script>
  </body>
</html>
